/**
 * 初始化请假申请详情对话框
 */
var LeaveApplyInfoDlg = {
    leaveApplyInfoData : {}
};

/**
 * 清除数据
 */
LeaveApplyInfoDlg.clearData = function() {
    this.leaveApplyInfoData = {};
}

/**
 * 设置对话框中的数据
 *
 * @param key 数据的名称
 * @param val 数据的具体值
 */
LeaveApplyInfoDlg.set = function(key, val) {
    this.leaveApplyInfoData[key] = (typeof val == "undefined") ? $("#" + key).val() : val;
    return this;
}

/**
 * 设置对话框中的数据
 *
 * @param key 数据的名称
 * @param val 数据的具体值
 */
LeaveApplyInfoDlg.get = function(key) {
    return $("#" + key).val();
}

/**
 * 关闭此对话框
 */
LeaveApplyInfoDlg.close = function() {
    parent.layer.close(window.parent.LeaveApply.layerIndex);
}

/**
 * 收集数据
 */
LeaveApplyInfoDlg.collectData = function() {
    this
    .set('id')
    .set('userId')
    .set('leaveTypeId')
    .set('startDate')
    .set('days')
    .set('endDate')
    .set('remarks')
    .set('approveStatus');
}

/**
 * 提交添加
 */
LeaveApplyInfoDlg.addSubmit = function() {

    this.clearData();
    this.collectData();

    //提交信息
    var ajax = new $ax(Feng.ctxPath + "/leaveApply/add", function(data){
        Feng.success("添加成功!");
        window.parent.LeaveApply.table.refresh();
        LeaveApplyInfoDlg.close();
    },function(data){
        Feng.error("添加失败!" + data.responseJSON.message + "!");
    });
    ajax.set(this.leaveApplyInfoData);
    ajax.start();
}

/**
 * 提交修改
 */
LeaveApplyInfoDlg.editSubmit = function() {

    this.clearData();
    this.collectData();

    //提交信息
    var ajax = new $ax(Feng.ctxPath + "/leaveApply/update", function(data){
        Feng.success("修改成功!");
        window.parent.LeaveApply.table.refresh();
        LeaveApplyInfoDlg.close();
    },function(data){
        Feng.error("修改失败!" + data.responseJSON.message + "!");
    });
    ajax.set(this.leaveApplyInfoData);
    ajax.start();
}

$(function() {
    $.ajax({
        async : false,
        type: "post",
        dataType:"json",
        url: "/processtypeDesc/list",
        success : function(data){
            //alert(data);
            $("#leaveTypeId").empty();
            /*$("#processTypeId").append($("<option value='0'>-请选择-</option>"));*/
            $.each(data,function (i,val) {
                $("#leaveTypeId").append($("<option value="+val.id+">"+val.name+"</option>"));
            })
        },
        error : function(msg){
            /*window.top.alert('发生错误...'+msg);*/
        }
    });
});
